package com.yaoran.userauth.utils;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.HashMap;
import java.util.Map;

@ApiModel(value = "result",description = "返回结果")
@Data
public class R<T>{
    private static final long serialVersionUID = 1L;

    @ApiModelProperty(value = "code")
    Integer code;
    @ApiModelProperty(value = "msg")
    String msg;
    @ApiModelProperty(value = "返回值")
    T data;

    public R() {
        this.code = 0;
        this.msg = "success";
    }
    public R (int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public R (T data) {
        this.code = 0;
        this.msg = "success";
        this.data = data;
    }

    public static R error() {
        return error(500, "未知异常，请联系管理员");
    }

    public static R error(String msg) {
        return error(500, msg);
    }

    public static R error(int code, String msg) {
        return new R(code, msg);
    }

    public static R ok(String msg) {
        return new R(msg);
    }

    public static <T> R<T> ok(T map) {
        return new R(map);
    }

    public static R ok() {
        return new R();
    }
}
